package com.woniuxy.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.woniuxy.DTO.AddCageDTO;
import com.woniuxy.domain.AlgsType;
import com.woniuxy.vo.AlgsCageSizeVO;
import com.woniuxy.vo.AlgsCageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.woniuxy.domain.AlgsCage;
import com.woniuxy.service.IAlgsCageService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 笼子（库存）Controller
 * 
 * @author ruoyi
 * @date 2023-03-22
 */
@RestController
@RequestMapping("/cage")
public class AlgsCageController extends BaseController
{
    @Autowired
    private IAlgsCageService algsCageService;

    /**
     * 查询笼子（库存）列表
     */
   // @RequiresPermissions("cage:cage:list")
    @GetMapping("/list")
    public TableDataInfo list(AlgsCage algsCage)
    {
        startPage();
        List<AlgsCageVO> list = algsCageService.selectAllCageList(algsCage);
        return getDataTable(list);
    }

    /**
     * 导出笼子（库存）列表
     */
   // @RequiresPermissions("cage:cage:export")
    @Log(title = "笼子（库存）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgsCage algsCage)
    {
        List<AlgsCage> list = algsCageService.selectAlgsCageList(algsCage);
        ExcelUtil<AlgsCage> util = new ExcelUtil<AlgsCage>(AlgsCage.class);
        util.exportExcel(response, list, "笼子（库存）数据");
    }

    /**
     * 获取笼子（库存）详细信息
     */
   // @RequiresPermissions("cage:cage:query")
    @GetMapping(value = "/{cageId}")
    public AjaxResult getInfo(@PathVariable("cageId") Long cageId)
    {
        return success(algsCageService.selectAlgsCageByCageId(cageId));
    }

    /**
     * 新增笼子（库存）
     */
  //  @RequiresPermissions("cage:cage:add")
    @Log(title = "笼子（库存）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddCageDTO addCageDTO)
    {
        int i = algsCageService.addCage(addCageDTO);
        return i!=0?AjaxResult.success(): AjaxResult.error();
    }

    /**
     * 修改笼子（库存）
     */
  //  @RequiresPermissions("cage:cage:edit")
    @Log(title = "笼子（库存）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlgsCage algsCage)
    {
        return toAjax(algsCageService.updateAlgsCage(algsCage));
    }

    /**
     * 删除笼子（库存）
     */
  //  @RequiresPermissions("cage:cage:remove")
    @Log(title = "笼子（库存）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cageIds}")
    public AjaxResult remove(@PathVariable Long[] cageIds)
    {
        return toAjax(algsCageService.deleteAlgsCageByCageIds(cageIds));
    }
    /**
     * 查询所有的笼子使用状态
     */
    // @RequiresPermissions("cage:cage:list")
    @GetMapping("/queryCageType")
    public AjaxResult queryCageType() {
        List<AlgsType> algsTypes = algsCageService.selectAllCageType();
        return AjaxResult.success(algsTypes);

    }

}
